<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>板块列表</title>
<script type="text/javascript" src="public/script/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
function addat(jid){
	var trs=$('table:eq(0)>tbody').children('tr').size();
	var tr="<tr align=\"center\"><td>"+(trs+1)+"</td><td><input type=\"text\" id=\"sat"+trs+"\" maxlength=\"50\" name=\"typename\" value=\""+$(jid).val()+"\" onkeyup=\"if(this.value!=document.getElementById('hat"+trs+"').value){document.getElementById('btn_save_"+trs+"').removeAttribute('disabled')}else{document.getElementById('btn_save_"+trs+"').setAttribute('disabled')}\"/><input type=\"hidden\" id=\"hat"+trs+"\" value=\""+$(jid).val()+"\"><input type=\"hidden\" id=\"hatid"+trs+"\" name=\"typeid\" value=\"\"></td><td>0</td><td><button onclick=\"this.setAttribute('disabled');\" id=\"btn_save_"+trs+"\" disabled>修改板块</button></td></tr>";
	 $.ajax({
		   type: "POST",
		   url: "manage_addAT.action",
		   data: "articleType.typeName="+$(jid).val(),
		   success: function(data){
		     alert(data["returnMsg"]);
			 $('table:eq(0)>tbody').append(tr);
			 $(jid).val("")
		   },
		   error:function(){
			   alert("网络故障！请稍后再尝试！");
		   }
		}); 
}
function updaat(jnid,jiid){
	 $.ajax({
		   type: "POST",
		   url: "manage_updaAT.action",
		   data: "articleType.typeId="+$(jiid).val()+"&articleType.typeName="+$(jnid).val(),
		   success: function(data){
		     alert(data["returnMsg"]);
		   },
		   error:function(){
			   alert("网络故障！请稍后再尝试！");
		   }
		}); 
}

</script>
</head>
<body>
	<fieldset>
	<span><label for="newType_1"><b>板块名称:</b></label><input type="text" name="typename" id="newType_1" maxlength="50" onkeyup="if(this.value.length>0){document.getElementById('btn_add').removeAttribute('disabled')}else{document.getElementById('btn_add').setAttribute('disabled')};"/><button id="btn_add" disabled onclick="addat('#newType_1');this.setAttribute('disabled');">添加新板块</button></span>
	</fieldset>
	<p/>
	<center>
		<table border="1" bordercolor="black" style="border-collapse:collapse;" width="100%">
		<thead>
			<th>序号</th>
			<th>板块名称</th>
			<th>文章数量</th>
			<th>操       作</th>
		</thead>
		<tbody>
				<s:iterator value="#data" var="d" status="st">
						<tr align="center">
							<td>
							<s:property value="#st.index+1"/>
							</td>
							<td>
							<input type="text" id="sat<s:property value="#st.index"/>" maxlength="50" name="typename" value="<s:property value="#d.typeName"/>" onkeyup="if(this.value!=document.getElementById('hat<s:property value="#st.index"/>').value){document.getElementById('btn_save_<s:property value="#st.index"/>').removeAttribute('disabled')}else{document.getElementById('btn_save_<s:property value="#st.index"/>').setAttribute('disabled')}"/>
							<input type="hidden" id="hat<s:property value="#st.index"/>" value="<s:property value="#d.typeName"/>">
							<input type="hidden" id="hatid<s:property value="#st.index"/>" name="typeid" value="<s:property value="#d.typeId"/>">
							</td>
							<td>
							<s:property value="#count[#st.index]"/>
							</td>
							<td>
							<button onclick="updaat('#sat<s:property value="#st.index"/>','#hatid<s:property value="#st.index"/>');this.setAttribute('disabled');" id="btn_save_<s:property value="#st.index"/>" disabled>修改板块</button>
							</td>
						</tr>
				</s:iterator>
			</tbody>
		</table>
		</center>
		<script type="text/javascript"></script>
</body>
</html>